package com.wms.wms.vo.request;

import com.wms.wms.entity.Product;
import com.wms.wms.vo.base.BaseRequestVO;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.validator.constraints.Range;
import org.springframework.beans.BeanUtils;

import javax.validation.constraints.DecimalMax;
import javax.validation.constraints.DecimalMin;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Objects;

/**
 * @author Chl
 * @version 1.0
 * @date 2019/12/19 9:33
 */
@Data
@EqualsAndHashCode(callSuper = false)
public class ProductRequestVO extends BaseRequestVO {

    @NotNull(message = "编号不能为空")
    @NotEmpty(message = "编号不能为空")
    private String id;

    @NotNull(message = "产品名称不能为空")
    @NotEmpty(message = "产品名称不能为空")
    private String name;

    @NotNull(message = "类别编号不能为空")
    @NotEmpty(message = "类别编号不能为空")
    private String typeId;

    @NotNull(message = "保质期不能为空")
    @Range(min = 1,max = 10000,message = "保质期天数不对")
    private Integer guaranteeTime;

    @NotNull(message = "价格不能为空")
    @DecimalMin(value = "0.1",message = "价格不对")
    @DecimalMax(value = "1000",message = "价格不对")
    private Double price;

    public static Product getEntity(ProductRequestVO vo){
        if(Objects.isNull(vo)){
            return null;
        }
        Product product=new Product();
        BeanUtils.copyProperties(vo,product);
        return product;
    }

}
